package com.youlu.campus.website.controller;

import com.youlu.campus.common.base.QResult;
import com.youlu.campus.website.entity.Partner;
import com.youlu.campus.website.entity.PartnerPageQuery;
import com.youlu.campus.website.service.PartnerService;
import org.springframework.data.domain.Page;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 合作伙伴控制层
 *
 * @author su
 * @date 2025/08/25
 */
@RestController
@RequestMapping("/website/partner")
public class PartnerController {

    @Resource
    private PartnerService partnerService;

    /**
     * 新增合作伙伴
     *
     * @param partner 合作伙伴实体
     * @return QResult<Partner>
     */
    @PostMapping("/save")
    public QResult<Partner> savePartner(@RequestBody Partner partner) {
        return QResult.success(partnerService.save(partner));
    }

    /**
     * 根据 ID 删除合作伙伴
     *
     * @param partner 合作伙伴 ID
     * @return QResult<Boolean>
     */
    @PostMapping("/delete")
    public QResult<Boolean> deletePartnerById(@RequestBody Partner partner) {
        Assert.hasText(partner.getId(), "合作伙伴 ID 不能为空");
        return QResult.success(partnerService.delete(partner.getId()));
    }


    /**
     * 根据 ID 查询合作伙伴详情
     *
     * @param id 合作伙伴 ID
     * @return QResult<Partner>
     */
    @GetMapping("/info")
    public QResult<Partner> getPartnerById(@RequestParam String id) {
        return QResult.success(partnerService.findById(id));
    }

    /**
     * 分页查询合作伙伴列表
     *
     * @param pageQuery
     * @return QResult<Page < Partner>>
     */
    @PostMapping("/find-page")
    public QResult<Page<Partner>> getPartnerPage(@RequestBody PartnerPageQuery pageQuery) {
        return QResult.success(partnerService.findByPage(pageQuery));
    }
}